package com.cloud.base.thread;

import lombok.SneakyThrows;

public class JoinMain {
    //t2线程t1.join 则 t2阻塞，等待t1结束在执行
    @SneakyThrows
    public static void main(String[] args) {
        //线程阻塞等待
        Thread t1 = new Thread(new Runnable() {
            @SneakyThrows
            public void run() {
                for (int i = 0; i < 20; i++) {
                    Thread.sleep(1000);
                    System.out.println("t1,i:" + i);
                }
            }
        });
        t1.start();
        Thread t2 = new Thread(new Runnable() {
            public void run() {
                try {
                    t1.join();
                } catch (Exception e) {
                    // TODO: handle exception
                }
                for (int i = 0; i < 20; i++) {
                    System.out.println("t2,i:" + i);
                }
            }
        });
        t2.start();
    }
}
